/*		Filename: 	logical_client.h
 *		Author:		彭望
 *		Date:		2012-01-09
 *		Use:		定义逻辑业务客户端的结构
 */
#ifndef	LOGICAL_CLIENT_H
#define LOGICAL_CLIENT_H

#include "public.h"
#include "message.pb.h"
#include "logger.h"
#include "net_manager.h"

class CLogicalClient
{
	public:
		CLogicalClient(const string& configFilename);
		RetCode_t Login(const CLoginInfo& info);
		RetCode_t Logout();
		RetCode_t QueryServer(const CQueryInfo& info);
		
	private:
		/*
		 *	向服务器请求的方法，负责将protobuf对象进行操作
		 */
		RetCode_t doQuery(const Request& req);

		/*
		 *	向服务器请求的具体实现，负责socket层操作
		 */
		RetCode_t doQueryRaw(const string& msg);
		/*
		 *  作为请求的回调函数
		 */ 
		void request_callback(istream& is, ostream& os);
		void connect_callback(bool isConnected);
		
	private:

		bool m_isInUse;
		string m_cardNo;
		
		string m_serverIp;
		short m_port;

		CNetManagerPtr m_nmPtr;
		Logger::Logger_t& logger;

		boost::mutex m_connectMutex;
};

#endif
